﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Lottery.Herper;
using Lottery.MediaData.Core;

namespace Lottery.MediaData.UI {
    /// <summary>
    /// 新增场次组合 窗体
    /// </summary>
    public partial class NewCCForm : Form {
        private string m_qiShu;
        
        public NewCCForm(string qiShu, int maxCount)
            : this() {
            m_qiShu = qiShu;
            this.MaxCount = maxCount;
            selectNice.MaxCount = maxCount;
        }

        private NewCCForm() {
            InitializeComponent();

            this.SetDialogStyle();
        }

        private void buttonOK_Click(object sender, EventArgs e) {
            if (!selectNice.IsOK) {
                var info = string.Format("选择的场次总和不等{0}，请重新选择", MaxCount);
                this.ShowInfo(info);
                selectNice.Focus();
                return;
            }

            if (this.ShowYesNoInfo("请确认是否新增场次") != DialogResult.Yes) {
                selectNice.Focus();
                return;
            }

            var cc = selectNice.CC;
            var list = DataHelper.LoadCC(m_qiShu, MaxCount);
            if (list.ToList().IndexOf(cc) == -1)
                DataHelper.SaveCC(m_qiShu, cc, MaxCount);

            this.CC = cc;
            DialogResult = DialogResult.OK;
        }

        /// <summary>
        /// 场次组合
        /// </summary>
        public string CC { get; set; }

        /// <summary>
        /// 最大场次
        /// </summary>
        public int MaxCount { get; set; }
    }
}
